<?php

class Admin_Model_DbTable_Courses extends Zend_Db_Table_Abstract {
	
	protected $_name = 'course';
	
	public function insertCourse($cname, $cno, $deptid, $catid, $schoolid){
		
		$data = array (
		'name' => $cname,
		'course_no' => $cno,
		'dept_id' => $deptid,
		'category_id' => $catid,
		'school_id' => $schoolid
		);
		
		$this->insert($data);
	}
	
    public function checkSubmission($courseno){
		$select = new Zend_Db_Select($this->_db);
		$courseno = $this->_db->quote($courseno);
		$result = $select->from(array('course'), array('val' =>'count(id)')) 
						->where('course_no ='. $courseno);
		$ff = $this->_db->fetchAll($result);
		return $ff;
    }
	/**
	 * deleteCourse
	 * This function is used to delete a particular course
	 * @param unknown_type $cid
	 */
	public function deleteCourse($cid){
		
		$this->delete('id =' . (int)$cid);
	}
	
	/**
	 * updateCourse
	 * This function helps to update a course
	 */
	public function updateCourse($id, $school, $dept, $cat, $courseNo, $courseName ){
		$data = array(
		'name' => $courseName,
		'course_no' => $courseNo
		);
		$this->update($data, 'id = '.$id);
	}
	
	public function getCourse($id)
	{
	$id = (int)$id;
	$row = $this->fetchRow('id = ' . $id);
	if (!$row) {
	throw new Exception("Count not find row $id");
	}
	return $row->toArray();
	}
	
}